<template>
	<view class="page">
		<view class="flex0">
			<u-navbar :fixed='false' bgColor="transparent" @leftClick="navBack" title="学生心理健康服务平台">
				<view slot="center" class="navTitle">
					学生心理健康服务平台
				</view>
			</u-navbar>
		</view>

		<view class="flex1">
			<scroll-view scroll-y="true" class="scrollView pt30">
				<div class="banner pd30" v-if="banner&&banner.length>0">
					<div class="banIn">
						<swiper :circular="true" :indicator-dots="true" :autoplay="true" :interval="3000"
							:duration="1000" indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#ff6e1f">
							<swiper-item @click="toBanner(item)" v-for="(item,index) in banner" :key="index">
								<image :src="item.picUrl" mode="aspectFill"></image>
							</swiper-item>
						</swiper>
					</div>
				</div>

				<view class="imgLinks pd30">
					<view @click="toBanner(item)" v-for="(item,index) in otherBanner" :key="index" class="item">
						<image :src="item.picUrl" mode="widthFix"></image>
					</view>
					<!-- <navigator url="" open-type="navigate" class="item">
						<image src="@/static/images/link2.png" mode="widthFix"></image>
					</navigator> -->
				</view>
				<view class="cepingList pd30" v-if="info.pendingWork">
					<view class="ceping">
						<view class="bg">
							<image src="https://bjsx.gzwhir.com/admin-api/infra/file/18/get/boxbg2.png" mode="aspectFill"></image>
						</view>
						<view class="tit">
							<view class="tl">
								<view class="t">
									{{info.pendingWork.title}}
								</view>
								<view class="p">
									{{info.pendingWork.endDate}}
								</view>
							</view>
							<view class="tr">
								待完成
							</view>
						</view>
						<view class="txt">
							<view class="xtit">
								<view class="xt">
									包含项目
								</view>
								<view class="num">
									<text class="cur">{{info.pendingWork.completed}}</text>
									<text>/</text>
									<text>{{info.pendingWork.total}}</text>
								</view>
							</view>
							<view class="xp">
								<u-line-progress height="10rpx" inactiveColor="#ffffff" activeColor="#fe9c29"
									:percentage="info.pendingWork.completed/info.pendingWork.total*100"
									:showText="false"></u-line-progress>
							</view>
						</view>
					</view>
				</view>
				<view class="taskBlock pd30" v-if="info.taskList&&info.taskList.length>0">
					<view class="box">
						<view class="tit">
							<image src="@/static/images/title4.png" mode="heightFix"></image>
						</view>
						<view class="taskList">
							<view class="item" v-for="task in info.taskList">
								<view class="date">
									{{task.date}}
								</view>
								<view class="ul">
									<view class="li" v-for="(i,index) in task.list">
										<view class="or">
											{{'任务'+orderNums[index]}}
										</view>
										<view class="lt">
											{{i.title}}
										</view>
										<view class="btn">
											去完成
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="floor pd30" v-if="knowledge&&knowledge.length>0">
					<view class="floorTit">
						<view class="tit">
							<image src="@/static/images/title1.png" mode="heightFix"></image>
						</view>
						<navigator :url="'/subpage/article/article?categoryId='+19" open-type="navigate" class="more">
							<text>更多</text>
							<view class="ico">
								<image src="@/static/images/icon-more.png" mode="aspectFit"></image>
							</view>
						</navigator>
					</view>
					<view class="floorCon">
						<scroll-view scroll-x="true" class="xScroller">
							<view class="xScrollFlex">
								<navigator :url="'/subpage/single/single?id='+i.id" open-type="navigate"
									class="knowledgeCard" v-for="(i,idx) in knowledge" :key="idx">
									<view class="bg">
										<image src="@/static/images/boxbg1.png" mode="aspectFit"></image>
									</view>
									<view class="ico">
										<image src="@/static/images/icon-quato.png" mode="aspectFit"></image>
									</view>
									<view class="txt">
										<view class="it">
											{{i.title}}
										</view>
										<view class="ip">
											{{i.introduction || ''}}
										</view>
									</view>
								</navigator>
							</view>
						</scroll-view>
					</view>
				</view>
				<view class="floor pd30 white" v-if="storyList&&storyList.length>0">
					<view class="floorTit">
						<view class="tit">
							<image src="@/static/images/title2.png" mode="heightFix"></image>
						</view>
						<navigator :url="'/subpage/article/article?categoryId='+20" open-type="navigate" class="more">
							<text>更多</text>
							<view class="ico">
								<image src="@/static/images/icon-more.png" mode="aspectFit"></image>
							</view>
						</navigator>
					</view>
					<view class="floorCon">
						<scroll-view scroll-x="true" class="xScroller">
							<view class="xScrollFlex">
								<navigator :url="'/subpage/single/single?id='+i.id" open-type="navigate"
									class="storyCard" v-for="(i,idx) in storyList" :key="idx">
									<view class="img">
										<image :src="i.picUrl" mode="widthFix"></image>
									</view>
									<view class="txt">
										<view class="it">
											{{i.title}}
										</view>
									</view>
								</navigator>
							</view>
						</scroll-view>
					</view>
				</view>
				<view class="floor pd30" v-if="articleList&&articleList.length>0">
					<view class="floorTit">
						<view class="tit">
							<image src="@/static/images/title3.png" mode="heightFix"></image>
						</view>
						<navigator :url="'/subpage/article/article?categoryId=1868285981104242689'" open-type="navigate" class="more">
							<text>更多</text>
							<view class="ico">
								<image src="@/static/images/icon-more.png" mode="aspectFit"></image>
							</view>
						</navigator>
					</view>
					<view class="floorCon">
						<scroll-view scroll-x="true" class="xScroller">
							<view class="xScrollFlex">
								<navigator :url="'/subpage/single/single?id='+i.id" open-type="navigate"
									class="normalCard" v-for="(i,idx) in articleList" :key="idx">
									<view class="img">
										<image :src="i.picUrl" mode="widthFix"></image>
									</view>
									<view class="txt">
										<view class="it">
											{{i.title}}
										</view>
										<view class="date">
											{{i.publishDate}}
										</view>
									</view>
								</navigator>
							</view>
						</scroll-view>
					</view>
				</view>
			</scroll-view>

		</view>
		<view class="flex0">
			<TabBar :active="0" type="tourist"></TabBar>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				banner: [],
				knowledge: [],
				storyList: [],
				articleList: [],
				otherBanner: [],
				personInfo: {},
				info: {}
			}
		},
		methods: {
			toBanner(item) {
				console.log(item, 121221)
				if (item.url && item.url.indexOf('http') >= 0) {
					uni.navigateTo({
						url: `/pages/webview/webview?src=${item.url}`
					})
				} else {
					uni.navigateTo({
						url: item.url
					})
				}
			},
			// 获取banner
			getBanner() {
				this.$api.adList({
					position: 6
				}, res => {
					if (res.code == 200) {
						this.banner = res.data;
						console.log(this.banner, 123141)
					}
				})
			},
			getOtherBanner() {
				if (this.personInfo.userType == 2) {

					this.$api.adList({
						position: 3
					}, res => {
						if (res.code == 200) {
							this.otherBanner = res.data;
						}
					})
				}

				if (this.personInfo.userType == 4) {

					this.$api.adList({
						position: 2
					}, res => {
						if (res.code == 200) {
							this.otherBanner = res.data;
						}
					})
				}
				if (this.personInfo.userType == 3) {

					this.$api.adList({
						position: 1
					}, res => {
						if (res.code == 200) {
							this.otherBanner = res.data;
						}
					})
				}

			},
			getInfo() {
				this.$api.articleList({
					pageNo: 1,
					pageSize: 10,
					categoryId:19
				}, res => {
					if (res.code == 200) {
						this.knowledge = res.data.list
					}
				})
				this.$api.articleList({
					pageNo: 1,
					pageSize: 10,
					categoryId: 20
				}, res => {
					if (res.code == 200) {
						this.storyList = res.data.list
					}
				})
				this.$api.articleList({
					pageNo: 1,
					pageSize: 10,
					categoryId: '1868285981104242689'
				}, res => {
					if (res.code == 200) {
						this.articleList = res.data.list
					}
				})

			}
		},
		onShow() {


			this.getBanner()
			this.getInfo();
			if (this.$db.get("userToken")) {
				this.$api.memberInfo({}, res => {
					if (res.code == 200) {
						this.personInfo = res.data;
						this.getOtherBanner()
					}
				})

			}
		},
	}
</script>

<style lang="scss" scoped>
	.banner {
		margin-bottom: 10rpx;

		.banIn {
			padding-bottom: 46.38%;
			position: relative;

			swiper {
				width: 100%;
				height: 100%;
				border-radius: 30rpx;
				overflow: hidden;
				position: absolute;
				left: 0;
				top: 0;

				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.normalCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		background: #fff !important;
		border-radius: 20rpx;
		overflow: hidden;
		white-space: normal;
		display: flex;
		flex-direction: column;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.img {
			flex: 0 0 auto;
			width: 100%;

			image {
				display: block;
				width: 100%;
				height: auto;
			}
		}

		.txt {
			padding: 25rpx;
			flex: 1 1 auto;
			box-sizing: border-box;
			width: 100%;
			display: flex;
			flex-direction: column;

			.it {
				margin-bottom: 30rpx;
				font-size: 28rpx;
				line-height: 40rpx;
				max-height: 120rpx;
				overflow: hidden;
				color: #7a6458;
				flex: 1 1 auto;
				width: 100%;
			}

			.date {
				width: 100%;
				font-size: 22rpx;
				color: #897f7a;
				flex: 0 0 auto;
			}
		}
	}

	.storyCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		background: rgba(0, 0, 0, 0.5) !important;
		;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		// background: none !important;
		border-radius: 20rpx;
		overflow: hidden;
		white-space: normal;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.img {
			image {
				display: block;
				width: 100%;
				height: auto;
			}
		}

		.txt {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			padding: 0 25rpx 30rpx;
			box-sizing: border-box;
			z-index: 10;

			.it {
				font-size: 32rpx;
				line-height: 40rpx;
				color: #fff;
				max-height: 160rpx;
				overflow: hidden;
			}
		}
	}

	.knowledgeCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		height: 330rpx;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		background: none !important;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: -1;

			image {
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		.ico {
			position: absolute;
			right: 30rpx;
			top: 20rpx;

			image {
				display: block;
				width: 85rpx;
				height: 60rpx;
			}
		}

		.txt {
			position: absolute;
			top: 125rpx;
			left: 0;
			width: 100%;
			bottom: 0;
			z-index: 5;
			padding: 0 25rpx 30rpx;
			box-sizing: border-box;
			white-space: normal;

			.it {
				font-size: 32rpx;
				line-height: 40rpx;
				max-height: 80rpx;
				overflow: hidden;
				color: #7a6458;
				margin-bottom: 20rpx;
			}

			.ip {
				font-size: 20rpx;
				line-height: 36rpx;
				max-height: 72rpx;
				overflow: hidden;
				color: #897f7a;
			}
		}
	}
</style>

<style lang="scss" scoped>
	.banner {
		margin-bottom: 10rpx;

		.banIn {
			padding-bottom: 46.38%;
			position: relative;

			swiper {
				width: 100%;
				height: 100%;
				border-radius: 30rpx;
				overflow: hidden;
				position: absolute;
				left: 0;
				top: 0;

				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.imgLinks {
		padding-top: 20rpx;
		display: flex;
		align-items: stretch;
		justify-content: space-between;
		margin-bottom: 20rpx;

		.item {
			border: none !important;
			opacity: 1 !important;
			outline: none !important;
			background: none !important;
			flex: 0 0 auto;
			width: 50%;
			display: flex;
			align-items: flex-end;
			justify-content: flex-start;

			image {
				display: block;
				width: 103%;
				height: auto;
				flex: 0 0 auto;
			}

			&:nth-child(2) {
				justify-content: flex-end;
			}
		}
	}

	.normalCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		background: #fff !important;
		border-radius: 20rpx;
		overflow: hidden;
		white-space: normal;
		display: flex;
		flex-direction: column;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.img {
			flex: 0 0 auto;
			width: 100%;

			image {
				display: block;
				width: 100%;
				height: auto;
			}
		}

		.txt {
			padding: 25rpx;
			flex: 1 1 auto;
			box-sizing: border-box;
			width: 100%;
			display: flex;
			flex-direction: column;

			.it {
				margin-bottom: 30rpx;
				font-size: 28rpx;
				line-height: 40rpx;
				max-height: 120rpx;
				overflow: hidden;
				color: #7a6458;
				flex: 1 1 auto;
				width: 100%;
			}

			.date {
				width: 100%;
				font-size: 22rpx;
				color: #897f7a;
				flex: 0 0 auto;
			}
		}
	}

	.storyCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		background: rgba(0, 0, 0, 0.5) !important;
		;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		// background: none !important;
		border-radius: 20rpx;
		overflow: hidden;
		white-space: normal;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.img {
			image {
				display: block;
				width: 100%;
				height: auto;
			}
		}

		.txt {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			padding: 0 25rpx 30rpx;
			box-sizing: border-box;
			z-index: 10;

			.it {
				font-size: 32rpx;
				line-height: 40rpx;
				color: #fff;
				max-height: 160rpx;
				overflow: hidden;
			}
		}
	}

	.knowledgeCard {
		flex: 0 0 auto;
		position: relative;
		width: 320rpx;
		height: 330rpx;
		z-index: 5;
		margin-right: 25rpx;
		border: none !important;
		opacity: 1 !important;
		outline: none !important;
		background: none !important;

		&:before,
		&:after {
			display: none;
		}

		&:last-child {
			margin-right: 0;
		}

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: -1;

			image {
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		.ico {
			position: absolute;
			right: 30rpx;
			top: 20rpx;

			image {
				display: block;
				width: 85rpx;
				height: 60rpx;
			}
		}

		.txt {
			position: absolute;
			top: 125rpx;
			left: 0;
			width: 100%;
			bottom: 0;
			z-index: 5;
			padding: 0 25rpx 30rpx;
			box-sizing: border-box;
			white-space: normal;

			.it {
				font-size: 32rpx;
				line-height: 40rpx;
				max-height: 80rpx;
				overflow: hidden;
				color: #7a6458;
				margin-bottom: 20rpx;
			}

			.ip {
				font-size: 20rpx;
				line-height: 36rpx;
				max-height: 72rpx;
				overflow: hidden;
				color: #897f7a;
			}
		}
	}
</style>